#ifndef __STC15F2K60S2_H_
#define __STC15F2K60S2_H_

#ifdef __SDCC 
#define SFR(reg, addr) __sfr __at(addr) reg
#define SBIT(reg, addr) __sbit __at(addr) reg
#define interrupt __interrupt
#define bit __bit  
#define _nop_() __asm NOP __endasm

#else//Keil
#define SFR(reg, addr) sfr reg = addr
#define SBIT(reg, addr) sbit reg = addr

// #define _nop_() \
// 	__asm     \
// 	nop   \
// 	__endasm 

#endif //End of __SDCC





SFR(ACC		,0xE0) ;
SFR(B			,0xF0) ;
SFR(PSW		,0xD0) ;
SFR(SP			,0x81) ;
SFR(DPL		,0x82) ;
SFR(DPH		,0x83) ;
SFR(P0			,0x80) ;
SFR(P1			,0x90) ;
SFR(P2			,0xA0) ;
SFR(P3			,0xB0) ;
SFR(P4			,0xC0) ;
SFR(P5			,0xC8) ;
SFR(P6			,0xE8) ;
SFR(P7			,0xF8) ;
SFR(P0M0		,0x94) ;
SFR(P0M1		,0x93) ;
SFR(P1M0		,0x92) ;
SFR(P1M1		,0x91) ;
SFR(P2M0		,0x96) ;
SFR(P2M1		,0x95) ;
SFR(P3M0		,0xB2) ;
SFR(P3M1		,0xB1) ;
SFR(P4M0		,0xB4) ;
SFR(P4M1		,0xB3) ;
SFR(P5M0		,0xCA) ;
SFR(P5M1		,0xC9) ;
SFR(P6M0		,0xCC) ;
SFR(P6M1		,0xCB) ;
SFR(P7M0		,0xE2) ;
SFR(P7M1		,0xE1) ;
SFR(PCON		,0x87) ;
SFR(AUXR		,0x8E) ;
SFR(AUXR1		,0xA2) ;
SFR(P_SW1		,0xA2) ;
SFR(CLK_DIV	,0x97) ;
SFR(BUS_SPEED	,0xA1) ;
SFR(P1ASF		,0x9D) ;
SFR(P_SW2		,0xBA) ;
SFR(IE			,0xA8) ;
SFR(IP			,0xB8) ;
SFR(IE2		,0xAF) ;
SFR(IP2		,0xB5) ;
SFR(INT_CLKO	,0x8F) ;
SFR(TCON		,0x88) ;
SFR(TMOD		,0x89) ;
SFR(TL0		,0x8A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MPCR2		,0xE7) ;
SFR(PWMCFG		,0xf1) ;
SFR(PWMCR		,0xf5) ;
SFR(PWMIF		,0xf6) ;
SFR(PWMFDCR	,    0xf7) ;
SFR( ISP_DATA  ,0xC2) ;
SFR( ISP_ADDRH ,0xC3) ;
SFR( ISP_ADDRL ,0xC4) ;
SFR( ISP_CMD   ,0xC5) ;
SFR( ISP_TRIG  ,0xC6) ;
SFR( ISP_CONTR ,0xC7) ;
SFR( PCON2   ,0x97) ;
SFR( TH4  , 0xD2 );
SFR( TL4  , 0xD3 );
SFR( TH3  , 0xD4 );
SFR( TL3  , 0xD5 );
SFR( TH2  , 0xD6 );
SFR( TL2  , 0xD7 );

SBIT( CY ,0xd7 );
SBIT( AC ,0xd6 );
SBIT( F0 ,0xd5 );
SBIT( RS1,0xd4 )  ;
SBIT( RS0,0xd3 ) ;
SBIT( OV ,0xd2 );
SBIT( P  ,0xd0 );
SBIT( P0_0,0x80 );
SBIT( P0_1,0x81 );
SBIT( P0_2,0x82 );
SBIT( P0_3,0x83 );
SBIT( P0_4,0x84 );
SBIT( P0_5,0x85 );
SBIT( P0_6,0x86 );
SBIT( P0_7,0x87 );
SBIT( P1_0,0x90 );
SBIT( P1_1,0x91 );
SBIT( P1_2,0x92 );
SBIT( P1_3,0x93 );
SBIT( P1_4,0x94 );
SBIT( P1_5,0x95 );
SBIT( P1_6,0x96 );
SBIT( P1_7,0x97 );
SBIT( P2_0,0xa0 );
SBIT( P2_1,0xa1 );
SBIT( P2_2,0xa2 );
SBIT( P2_3,0xa3 );
SBIT( P2_4,0xa4 );
SBIT( P2_5,0xa5 );
SBIT( P2_6,0xa6 );
SBIT( P2_7,0xa7 );
SBIT( P3_0,0xb0 );
SBIT( P3_1,0xb1 );
SBIT( P3_2,0xb2 );
SBIT( P3_3,0xb3 );
SBIT( P3_4,0xb4 );
SBIT( P3_5,0xb5 );
SBIT( P3_6,0xb6 );
SBIT( P3_7,0xb7 );
SBIT( P4_0,0xc0 );
SBIT( P4_1,0xc1 );
SBIT( P4_2,0xc2 );
SBIT( P4_3,0xc3 );
SBIT( P4_4,0xc4 );
SBIT( P4_5,0xc5 );
SBIT( P4_6,0xc6 );
SBIT( P4_7,0xc7 );
SBIT( P5_0,0xc8 );
SBIT( P5_1,0xc9 );
SBIT( P5_2,0xca );
SBIT( P5_3,0xcb );
SBIT( P5_4,0xcc );
SBIT( P5_5,0xcd );
SBIT( P5_6,0xce );
SBIT( P5_7,0xcf );
SBIT( P6_0,0xe8 );
SBIT( P6_1,0xe9 );
SBIT( P6_2,0xea );
SBIT( P6_3,0xeb );
SBIT( P6_4,0xec );
SBIT( P6_5,0xed );
SBIT( P6_6,0xee );
SBIT( P6_7,0xef );
SBIT( P7_0,0xf8 );
SBIT( P7_1,0xf9 );
SBIT( P7_2,0xfa );
SBIT( P7_3,0xfb );
SBIT( P7_4,0xfc );
SBIT( P7_5,0xfd );
SBIT( P7_6,0xfe );
SBIT( P7_7,0xff );
SBIT( EA  ,0xaf );
SBIT( ELVD,0xae );
SBIT( EADC,0xad );
SBIT( ES  ,0xac );
SBIT( ET1 ,0xab );
SBIT( EX1 ,0xaa );
SBIT( ET0 ,0xa9 );
SBIT( EX0 ,0xa8 );
SBIT( PPCA,0xbf );
SBIT( PLVD,0xbe );
SBIT( PADC,0xbd );
SBIT( PS  ,0xbc );
SBIT( PT1,0xbb );
SBIT( PX1,0xba );
SBIT( PT0,0xb9 );
SBIT( PX0,0xb8 );
SBIT( TF1,0x8f );
SBIT( TR1,0x8e );
SBIT( TF0,0x8d );
SBIT( TR0,0x8c );
SBIT( IE1,0x8b );
SBIT( IT1,0x8a );
SBIT( IE0,0x89 );
SBIT( IT0,0x88 );
SBIT( SM0,0x9f );
SBIT( SM1,0x9e );
SBIT( SM2,0x9d );
SBIT( REN,0x9c );
SBIT( TB8,0x9b );
SBIT( RB8,0x9a );
SBIT( TI,0x99 );
SBIT( RI,0x98 );
SBIT( CF,0xdf );
SBIT( CR,0xde );
SBIT( CCF2,0xda );
SBIT( CCF1,0xd9 );
SBIT( CCF0,0xd8 );


#define ISP_EN			(1<<7)
#define ISP_SWBS		(1<<6)
#define ISP_SWRST		(1<<5)
#define ISP_CMD_FAIL	(1<<4)
#define ISP_WAIT_1MHZ	7
#define ISP_WAIT_2MHZ	6
#define ISP_WAIT_3MHZ	5
#define ISP_WAIT_6MHZ	4
#define ISP_WAIT_12MHZ	3
#define ISP_WAIT_20MHZ	2
#define ISP_WAIT_24MHZ	1
#define ISP_WAIT_30MHZ	0


#define  P00 P0_0
#define  P01 P0_1
#define  P02 P0_2
#define  P03 P0_3
#define  P04 P0_4
#define  P05 P0_5
#define  P06 P0_6
#define  P07 P0_7
#define  P10 P1_0
#define  P11 P1_1
#define  P12 P1_2
#define  P13 P1_3
#define  P14 P1_4
#define  P15 P1_5
#define  P16 P1_6
#define  P17 P1_7
#define  P20 P2_0
#define  P21 P2_1
#define  P22 P2_2
#define  P23 P2_3
#define  P24 P2_4
#define  P25 P2_5
#define  P26 P2_6
#define  P27 P2_7
#define  P30 P3_0
#define  P31 P3_1
#define  P32 P3_2
#define  P33 P3_3
#define  P34 P3_4
#define  P35 P3_5
#define  P36 P3_6
#define  P37 P3_7
#define  P40 P4_0
#define  P41 P4_1
#define  P42 P4_2
#define  P43 P4_3
#define  P44 P4_4
#define  P45 P4_5
#define  P46 P4_6
#define  P47 P4_7
#define  P50 P5_0
#define  P51 P5_1
#define  P52 P5_2
#define  P53 P5_3
#define  P54 P5_4
#define  P55 P5_5
#define  P56 P5_6
#define  P57 P5_7
#define  P60 P6_0
#define  P61 P6_1
#define  P62 P6_2
#define  P63 P6_3
#define  P64 P6_4
#define  P65 P6_5
#define  P66 P6_6
#define  P67 P6_7
#define  P70 P7_0
#define  P71 P7_1
#define  P72 P7_2
#define  P73 P7_3
#define  P74 P7_4
#define  P75 P7_5
#define  P76 P7_6


#define		ENABLE		1
#define		DISABLE		0

#define	PolityLow			0	//低优先级中断
#define	PolityHigh			1	//高优先级中断

/*   interrupt vector */
#define		INT0_VECTOR		0
#define		TIMER0_VECTOR	1
#define		INT1_VECTOR		2
#define		TIMER1_VECTOR	3
#define		UART1_VECTOR	4
#define		ADC_VECTOR		5
#define		LVD_VECTOR		6
#define		PCA_VECTOR		7
#define		UART2_VECTOR	8
#define		SPI_VECTOR		9
#define		INT2_VECTOR		10
#define		INT3_VECTOR		11
#define		TIMER2_VECTOR	12
#define		INT4_VECTOR		16
#define		UART3_VECTOR	17
#define		UART4_VECTOR	18
#define		TIMER3_VECTOR	19
#define		TIMER4_VECTOR	20
#define		CMP_VECTOR		21

#define NOP1()  _nop_()
#define NOP2()  NOP1(),NOP1()
#define NOP3()  NOP2(),NOP1()
#define NOP4()  NOP3(),NOP1()
#define NOP5()  NOP4(),NOP1()
#define NOP6()  NOP5(),NOP1()
#define NOP7()  NOP6(),NOP1()
#define NOP8()  NOP7(),NOP1()
#define NOP9()  NOP8(),NOP1()
#define NOP10() NOP9(),NOP1()
#define NOP11() NOP10(),NOP1()
#define NOP12() NOP11(),NOP1()
#define NOP13() NOP12(),NOP1()
#define NOP14() NOP13(),NOP1()
#define NOP15() NOP14(),NOP1()
#define NOP16() NOP15(),NOP1()
#define NOP17() NOP16(),NOP1()
#define NOP18() NOP17(),NOP1()
#define NOP19() NOP18(),NOP1()
#define NOP20() NOP19(),NOP1()
#define NOP21() NOP20(),NOP1()
#define NOP22() NOP21(),NOP1()
#define NOP23() NOP22(),NOP1()
#define NOP24() NOP23(),NOP1()
#define NOP25() NOP24(),NOP1()
#define NOP26() NOP25(),NOP1()
#define NOP27() NOP26(),NOP1()
#define NOP28() NOP27(),NOP1()
#define NOP29() NOP28(),NOP1()
#define NOP30() NOP29(),NOP1()
#define NOP31() NOP30(),NOP1()
#define NOP32() NOP31(),NOP1()
#define NOP33() NOP32(),NOP1()
#define NOP34() NOP33(),NOP1()
#define NOP35() NOP34(),NOP1()
#define NOP36() NOP35(),NOP1()
#define NOP37() NOP36(),NOP1()
#define NOP38() NOP37(),NOP1()
#define NOP39() NOP38(),NOP1()
#define NOP40() NOP39(),NOP1()
#define NOP(N)  NOP##N()


#if (MAIN_Fosc >= 24000000L)
	#define		ISP_WAIT_FREQUENCY	ISP_WAIT_30MHZ
#elif (MAIN_Fosc >= 20000000L)
	#define		ISP_WAIT_FREQUENCY	ISP_WAIT_24MHZ
#elif (MAIN_Fosc >= 12000000L)
	#define		ISP_WAIT_FREQUENCY	ISP_WAIT_20MHZ
#elif (MAIN_Fosc >= 6000000L)
	#define		ISP_WAIT_FREQUENCY	ISP_WAIT_12MHZ
#elif (MAIN_Fosc >= 3000000L)
	#define		ISP_WAIT_FREQUENCY	ISP_WAIT_6MHZ
#elif (MAIN_Fosc >= 2000000L)
	#define		ISP_WAIT_FREQUENCY	ISP_WAIT_3MHZ
#elif (MAIN_Fosc >= 1000000L)
	#define		ISP_WAIT_FREQUENCY	ISP_WAIT_2MHZ
#else
	#define		ISP_WAIT_FREQUENCY	ISP_WAIT_1MHZ
#endif

#define 	ISP_TRIG()	ISP_TRIG = 0x5A,	ISP_TRIG = 0xA5		//ISP触发命令

#define		ISP_STANDBY()	ISP_CMD = 0		//ISP空闲命令（禁止）
#define		ISP_READ()		ISP_CMD = 1		//ISP读出命令
#define		ISP_WRITE()		ISP_CMD = 2		//ISP写入命令
#define		ISP_ERASE()		ISP_CMD = 3		//ISP擦除命令

typedef unsigned char   u8  ;
typedef unsigned short  u16 ;
typedef unsigned long   u32 ;
#endif
